home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 June: Reference Library / Dev.CD Jun 99 RL Disk 1.toast / What's New / Development Kits / Mac_OS_USB_DDK_v1.2 / Examples / CompositeClassDriver / CompositeDriverDescription.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-15  |  7.1 KB  |  238 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CompositeDriverDescription.c
  3.  
  4.     Contains:    Composite Class Driver Definition Header
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1997-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <Types.h>
  13. #include <Devices.h>
  14. #include <DriverServices.h>
  15. #include <USB.h>
  16.  
  17.  
  18. #include "CompositeClassDriver.h"
  19. #include "CompositeClassVersion.h"
  20.  
  21. usbCompositePBStruct newInterfacesPB;
  22.  
  23.  
  24. OSStatus CompositeDriverInitInterface(
  25.             UInt32                         interfaceNum, 
  26.             USBInterfaceDescriptor        *interfaceDesc, 
  27.             USBDeviceDescriptor            *deviceDesc, 
  28.             USBDeviceRef                 device);
  29.  
  30. //------------------------------------------------------
  31. //
  32. //    This is the driver description structure that the expert looks for first.
  33. //  If it's here, the information within is used to match the driver
  34. //  to the device whose descriptor was passed to the expert.
  35. //    Information in this block is also used by the expert when an
  36. //  entry is created in the Name Registry.
  37. //
  38. //------------------------------------------------------
  39. USBDriverDescription    TheUSBDriverDescription = 
  40. {
  41.     // Signature info
  42.     kTheUSBDriverDescriptionSignature,
  43.     kInitialUSBDriverDescriptor,
  44.     
  45.     // Device Info
  46.     0,                                        // vendor = not device specific
  47.     0,                                        // product = not device specific
  48.     0,                                        // version of product = not device specific
  49.     0,                                        // protocol = not device specific
  50.     
  51.     // Interface Info    (* I don't think this would always be required...*)                
  52.     0,                                        // Configuration Value
  53.     0,                                        // Interface Number
  54.     0,                                        // Interface Class
  55.     0,                                         // Interface SubClass
  56.     0,                                        // Interface Protocol
  57.         
  58.     
  59.     // Driver Info
  60.     "\pUSBCompositeDevice"kCMPStringVersShort,    // Driver name for Name Registry
  61.     kUSBCompositeClass,                            // Device Class  (from USBDeviceDefines.h)
  62.     kUSBCompositeSubClass,                        // Device Subclass 
  63.     kCMPHexMajorVers, 
  64.     kCMPHexMinorVers, 
  65.     kCMPCurrentRelease, 
  66.     kCMPReleaseStage,                        // version of driver
  67.     
  68.     // Driver Loading Info
  69.     kUSBDoNotMatchInterface                    // Please don't load us as an interface driver.
  70. };
  71.  
  72. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  73. {
  74.     kClassDriverPluginVersion,                // Version of this structure
  75.     CompositeDriverValidateHW,                // Hardware Validation Procedure
  76.     CompositeDriverInitialize,                // Initialization Procedure
  77.     CompositeDriverInitInterface,            // Interface Initialization Procedure
  78.     CompositeDriverFinalize,                // Finalization Procedure
  79.     CompositeDriverNotifyProc                // Driver Notification Procedure
  80. };
  81.  
  82. // hubDriverInitInterface function
  83. // Called to initialize driver for an individual interface - either by expert or
  84. // internally by driver
  85. OSStatus CompositeDriverInitInterface(
  86.             UInt32                         interfaceNum, 
  87.             USBInterfaceDescriptor        *interfaceDesc, 
  88.             USBDeviceDescriptor            *deviceDesc, 
  89.             USBDeviceRef                 device)
  90. {
  91. #pragma unused (interfaceNum)
  92. #pragma unused (interfaceDesc)
  93. #pragma unused (deviceDesc)
  94. #pragma unused (device)
  95.  
  96.     return (OSStatus)kUSBNoErr;
  97. }
  98.  
  99. OSStatus    CompositeDriverNotifyProc(UInt32     notification, void *pointer, UInt32 refcon)
  100. {
  101. #pragma unused (pointer)
  102. #pragma unused (refcon)
  103.  
  104. OSStatus    myErr;
  105. OSStatus     status = kUSBNoErr;
  106. UInt32        count = 0;
  107. static    UInt32    interfacenum = 0;
  108.  
  109.     switch (notification)
  110.     {
  111.         case kNotifyExpertTerminating:                                // TCC <USB15>
  112.                 newInterfacesPB.expertTerminatePending = true;
  113.                 while (count < newInterfacesPB.interfaceCount)
  114.                         USBExpertRemoveInterfaceDriver(newInterfacesPB.interfaceRefArray[count++]);
  115.                 return(noErr);
  116.             break;
  117.         case kNotifyDriverBeingRemoved:
  118.             newInterfacesPB.driverRemovalPending = true;
  119.             
  120.             if (newInterfacesPB.pb.usbRefcon & kCompletionPending)
  121.             {
  122.                 USBExpertStatus(newInterfacesPB.deviceRef, kCompositeDriverName": Waiting for transaction to complete", newInterfacesPB.pb.usbRefcon);
  123.                 status = kUSBDeviceBusy;
  124.             }
  125.             else
  126.             {
  127.                 if (interfacenum == 0)
  128.                     newInterfacesPB.pb.usbStatus = kUSBNoErr;
  129.                 
  130.                 if (newInterfacesPB.pb.usbStatus == kUSBPending)
  131.                 {
  132.                     USBExpertStatus(newInterfacesPB.deviceRef, kCompositeDriverName": Waiting for Dispose/Deallocate to complete", newInterfacesPB.pb.usbRefcon);
  133.                     status = kUSBDeviceBusy;
  134.                 }
  135.                 else
  136.                 {
  137.                     if (interfacenum < newInterfacesPB.interfaceCount)        
  138.                     {
  139.                         USBExpertRemoveInterfaceDriver(newInterfacesPB.interfaceRefArray[interfacenum]);
  140.                         InitParamBlock(newInterfacesPB.interfaceRefArray[interfacenum], &newInterfacesPB.pb);
  141.                         newInterfacesPB.pb.usbRefcon = 0;             
  142.                         newInterfacesPB.pb.usbCompletion = (USBCompletion)kUSBNoCallBack;
  143.                         myErr = USBDisposeInterfaceRef(&newInterfacesPB.pb);
  144.                         if(immediateError(myErr))
  145.                         {
  146.                             USBExpertFatalError(newInterfacesPB.interfaceRefArray[interfacenum], kUSBInternalErr, kCompositeDriverName" - USBDisposeInterfaceRef - immediate error", myErr);
  147.                         }
  148.                         interfacenum++;
  149.                         status = kUSBDeviceBusy;
  150.                     }
  151.                     else
  152.                     {
  153.                         if (newInterfacesPB.pFullConfigDescriptor)
  154.                         {
  155.                             InitParamBlock(newInterfacesPB.deviceRef, &newInterfacesPB.pb);
  156.                             newInterfacesPB.pb.usbRefcon = 0;             
  157.                             newInterfacesPB.pb.usbBuffer = newInterfacesPB.pFullConfigDescriptor;        
  158.                             newInterfacesPB.pb.usbCompletion = (USBCompletion)kUSBNoCallBack;
  159.                             myErr = USBDeallocMem(&newInterfacesPB.pb);
  160.                             newInterfacesPB.pFullConfigDescriptor = nil;
  161.                             status = kUSBDeviceBusy;
  162.                         }
  163.                         else
  164.                         {
  165.                             status = kUSBNoErr;
  166.                         }
  167.                     }
  168.                 }
  169.             }
  170.             break;
  171.             
  172.         default:
  173.             break;
  174.     }
  175.     return status;
  176. }
  177.  
  178. // Hardware Validation
  179. // Called upon load by Expert
  180. OSStatus CompositeDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
  181. {
  182. #pragma unused (device)
  183. #pragma unused (desc)
  184.  
  185.     return (OSStatus)kUSBNoErr;
  186. }
  187.  
  188. // Initialization function
  189. // Called upon load by Expert
  190. OSStatus     CompositeDriverInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc,  UInt32 busPowerAvailable)
  191. {
  192.     // don't let a race condition occur; prevent finalizing until we're all done.
  193.     DeviceInitialize(device, pDesc, busPowerAvailable);
  194.     return (OSStatus)kUSBNoErr;
  195. }
  196.  
  197. // Termination function
  198. // Called by Expert when driver is being shut down
  199. OSStatus CompositeDriverFinalize(USBDeviceRef theDeviceRef, USBDeviceDescriptorPtr pDesc)
  200. {
  201. #pragma unused (pDesc)
  202.  
  203.     USBExpertStatus(theDeviceRef, kCompositeDriverName" - Finalize", 0);
  204.     return (OSStatus)kUSBNoErr;
  205. }
  206.  
  207. void DeviceInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDeviceDescriptor, UInt32 busPowerAvailable)
  208. {
  209. static Boolean beenThereDoneThat = false;
  210.  
  211.     if(beenThereDoneThat)
  212.     {
  213.         USBExpertFatalError(device, kUSBInternalErr, kCompositeDriverName" is not reentrant!", 0);
  214.         return;
  215.     }
  216.     beenThereDoneThat = true;
  217.     
  218.     newInterfacesPB.driverRemovalPending = false;
  219.     newInterfacesPB.expertTerminatePending = false;
  220.     
  221.     newInterfacesPB.deviceRef = device;    
  222.     newInterfacesPB.deviceDescriptor = *pDeviceDescriptor;    
  223.     
  224.     newInterfacesPB.busPowerAvailable = busPowerAvailable;                            
  225.     newInterfacesPB.delayLevel = 0;                            
  226.     newInterfacesPB.transDepth = 0;                            
  227.     newInterfacesPB.retryCount = kCompositeRetryCount;
  228.     newInterfacesPB.pFullConfigDescriptor = nil;
  229.     
  230.     InitParamBlock(device, &newInterfacesPB.pb);
  231.     newInterfacesPB.pb.usbRefcon = kGetFullConfiguration0;            /* Start out at first state */
  232.     
  233. //    DebugStr("\pIn Composite Driver");
  234.     CompositeDeviceInitiateTransaction(&newInterfacesPB.pb);
  235. }
  236.  
  237.  
  238.